package operation;

import book.bookList;

import java.util.Scanner;

/**
 * @Author @fiber-cloud
 * @Date 2025/7/13 15:32
 * 借阅图书
 */
public class BorrowOperation implements IOperation{

    @Override
    public void work(bookList booklist) {
        System.out.println("借阅图书");

        System.out.println("请输入你要借阅图书的书名");
        Scanner sc = new Scanner(System.in);
        String bookName = sc.nextLine();

        for (int i = 0; i < booklist.getCount(); i++) {
            if (bookName.equals(booklist.getBooks(i).getName())){
                //说明有这本书
                if (booklist.getBooks(i).getBorrowed() == false){
                    //说明这本书还没被借阅
                    booklist.getBooks(i).setBorrowing(true);
                    System.out.println("成功借阅" + "《"+ bookName + "》");
                    return;
                }else {
                    System.out.println("抱歉！ " + "《"+ bookName + "》"+"已被借阅");
                }
            }
        }
        System.out.println("未找到"+ "《"+ bookName + "》");
    }
}
